package com.demohomework.homeworkdemo.service.impl;

import com.demohomework.homeworkdemo.mapper.CourseMapper;
import com.demohomework.homeworkdemo.pojo.Assignment;
import com.demohomework.homeworkdemo.pojo.Course;
import com.demohomework.homeworkdemo.service.CourseService;
import com.demohomework.homeworkdemo.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public void add(Course course) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        course.setId(id);
        courseMapper.add(course);
    }

    @Override
    public List<Course> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        return courseMapper.list(id);
    }

    @Override
    public Course findId(Integer id) {
        return courseMapper.findId(id);
    }

    @Override
    public void update(Course course) {
        courseMapper.update(course);
    }

    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }

    @Override
    public List<Course> selectByTeacherId(Integer teacherId) {
        return courseMapper.selectByTeacherId(teacherId);
    }

}
